//
//  WorkQuestionView.m
//  TeamInformatization
//
//  Created by bigger on 2019/4/2.
//  Copyright © 2019年 SPIC. All rights reserved.
//

#import "WorkQuestionView.h"

@interface WorkQuestionView ()

// 问题图片
@property (nonatomic, strong) UIImageView *questionImageView;
// 问题语音播放
@property (nonatomic, strong) UIButton *voicePlayButton;
// 问题描述
@property (nonatomic, strong) SimpleLabel *questionDescLabel;

// 展示数组
@property (nonatomic, strong) NSArray *showArray;


@end


@implementation WorkQuestionView

- (instancetype)initWithShowType:(int)showType
{
    if (self = [super init]) {
        self.backgroundColor = [UIColor whiteColor];
        
        switch (showType) {
            case 1: {
                self.showArray = @[@"类 型:", @"地 点:", @"提报人:", @"时间:", @"整改期限:", @"完成时间:"];
                break;
            }
            case 2: {
                self.showArray = @[@"类 型:", @"地 点:", @"提报人:", @"提报时间:", @"整改期限:", @"完成时间:", @"接受人:", @"接受时间:"];
                break;
            }
            case 3: {
                self.showArray = @[@"类 型:", @"地 点:", @"提报人:", @"提报时间:", @"整改期限:", @"完成时间:", @"整改人", @"整改时间", @"确认人:", @"确认时间:"];
                break;
            }
            case 4: {
                self.showArray = [NSArray array];
                break;
            }
            default:
                break;
        }
        
        [self creatViews];
    }
    return self;
}


- (void)creatViews
{
    NSString *title = @"整改事项图片";
    NSString *subTitle = @"问题描述";
    if (_showArray.count == 10) {
        title = @"整改处理后";
        subTitle = @"整改情况";
    }
    // 标题
    SimpleLabel *titleLabel = [SimpleLabel initWithText:title TextColor:kTitleTextColor TextFont: [UIFont fontWithName:@"PingFangSC-Medium" size: 15] TextAlignment:NSTextAlignmentLeft];
    [self addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15 * kScaleWidth);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(58 * kScaleWidth);
    }];
    
    //
    self.questionImageView = [[UIImageView alloc] init];
    [self addSubview:_questionImageView];
    [_questionImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom);
        make.centerX.mas_equalTo(self);
        make.size.mas_equalTo(CGSizeMake(kScreenWidth - 30 * kScaleWidth, 184 * kScaleWidth));
    }];
    
    //
    SimpleLabel *textLabel = [SimpleLabel initWithText:subTitle TextColor:kTitleTextColor TextFont: [UIFont fontWithName:@"PingFangSC-Medium" size: 15] TextAlignment:NSTextAlignmentLeft];
    [self addSubview:textLabel];
    [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(titleLabel);
        make.top.mas_equalTo(self.questionImageView.mas_bottom);
        make.height.mas_equalTo(51 * kScaleWidth);
    }];
    
    // 播放按钮
    self.voicePlayButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_voicePlayButton setBackgroundImage:[UIImage imageNamed:@"playVoice"] forState:UIControlStateNormal];
    [self addSubview:_voicePlayButton];
    [_voicePlayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(textLabel.mas_bottom);
        make.centerX.mas_equalTo(self);
        make.size.mas_equalTo(CGSizeMake(kScreenWidth - 30 * kScaleWidth, 36 * kScaleWidth));
    }];
    
    //
    self.questionDescLabel = [SimpleLabel initWithText:@"睡觉觉奥斯卡来得及看撒娇的开始就俺俩的健身卡" TextColor:kSetRGBColor(102, 102, 102, 1) TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size: 14] TextAlignment:NSTextAlignmentLeft];
    _questionDescLabel.numberOfLines = 0;
    [self addSubview:_questionDescLabel];
    [_questionDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.voicePlayButton.mas_bottom).offset(25 * kScaleWidth);
        make.left.mas_equalTo(15 * kScaleWidth);
        make.right.mas_equalTo(-15 * kScaleWidth);
        if (self.showArray.count == 0) {
            make.bottom.mas_equalTo(-10 * kScaleWidth);
        }
        
    }];
    
    
    if (self.showArray.count > 0) {
        // 分割线
        UILabel *lineLabel = [[UILabel alloc] init];
        lineLabel.backgroundColor = kCommonBGGaryColor;
        [self addSubview:lineLabel];
        [lineLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.questionDescLabel.mas_bottom).offset(14 * kScaleWidth);
            make.left.mas_equalTo(15 * kScaleWidth);
            make.right.mas_equalTo(-15 * kScaleWidth);
            make.height.mas_equalTo(0.5);
        }];
        
        
        
        for (int i = 0; i < _showArray.count; i++) {
            
            SimpleLabel *textLabel = [SimpleLabel initWithText:_showArray[i] TextColor:kTextAll102Color TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size: 13] TextAlignment:NSTextAlignmentLeft];
            [self addSubview:textLabel];
            [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(lineLabel.mas_bottom).offset(17 * kScaleWidth + 30 * kScaleWidth * i);
                make.left.mas_equalTo(15 * kScaleWidth);
            }];
            
            SimpleLabel *contentLabel = [SimpleLabel initWithText:@"" TextColor:kTitleTextColor TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size: 13] TextAlignment:NSTextAlignmentLeft];
            contentLabel.tag = 2200 + i;
            [self addSubview:contentLabel];
            [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(textLabel.mas_top);
                make.left.mas_equalTo(textLabel.mas_right).offset(5 * kScaleWidth);
            }];
            
            if (i == _showArray.count - 1) {
                [textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.bottom.mas_equalTo(-20 * kScaleWidth);
                }];
            }
        }
        
    }
    
}

- (void)setsd
{
    
}


- (void)setShowDataWithText:(NSString *)str
{
    _questionDescLabel.text = str;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
